import CMap from "./CMap";

/**
 * 事件管理
 */
 export default class CEvent {

    static eventMap:CMap = new CMap()

    /**
        注册
     */
    static on(key: any, callback:Function,target?: any){
        CEvent.eventMap.set(key+"",callback)
    }

    /**
        调用
     */
    static emit(key: any, data?: any){
        let callback = CEvent.eventMap.get(key+"")
        if(callback){
            callback(data)
        }
    }

    /**
        销毁
     */
    static off(...key:any){
        for (let i = 0; i < key.length; i++) {
            CEvent.eventMap.remove(key[i]+"")
        }
    }

}